package offer;

public class offerII_0020 {
    public int countSubstrings(String s) {
        int len=s.length();
        int[] num=new int[1];
        if(len==1) return 1;
        one(num,len,s);
        two(num,len,s);
        return num[0];
    }
    public void one(int[] num,int len,String s){
        for(int i=0;i<len;++i){
            int left=i;
            int right=i;
            while(left>=0&&right<len){
                if(s.charAt(left)==s.charAt(right)) {
                    num[0]++;
                    left--;
                    right++;
                }
                else break;

            }
        }
    }
    public void two(int[] num,int len,String s){
        for(int i=0;i<len-1;++i){
            int left=i;
            int right=i+1;
            while(left>=0&&right<len){
                if(s.charAt(left)==s.charAt(right)) {
                    num[0]++;
                    left--;
                    right++;
                }
                else break;

            }
        }
    }
}
